#pragma once
#include <vector>
#include <string>
#include <unordered_map>
#include "netcdfcpp.h"
#include "ncvalues.h"
#include "config.h"
#include <iostream>
#include "MyData.h"
#include "omp.h"
#include "io.h"
#include <fstream>
#include <thread>
#include <chrono>
#include <mutex>

class MyNc4Parse
{
public:
	explicit MyNc4Parse(const char* = "E:\\科研数据\\merra2_3d\\");
	~MyNc4Parse() {};
	MyNc4Parse(MyNc4Parse const&) = delete;
	MyNc4Parse& operator = (MyNc4Parse const&) = delete;

	auto inst3_3d_aer_single3d(const char* nc_name,const char* values,Coord3Dt &coordinate) -> int;
	auto inst3_3d_aer_single_multi3d(const char* nc_name, const char* values, std::vector<Coord3Dt> &coordsets) -> int;
	//解析4d数据
	auto inst3_3d_aer_single4d(const char* nc_name, const char* values, Coord4Dt& coordinate) -> int;
	auto inst3_3d_aer_single4d_useC() -> int;
	auto stat2_2d_pct(const char* nc_name) -> int;
	//查询一个2D点对应的值，参数：nc文件名,待查询变量名，2D坐标
	auto stat2_2d_pct_single(const char* nc_name, const char* values, Coord2Dt &coordinate) -> int;
	//查询多个2D点云数据对应的值
	auto stat2_2d_pct_multi(const char* nc_name, const char* values, std::vector<Coord2Dt> &coordsets) -> int;

public:
	//解析M2TMNXAER.5.12.4:MERRA2_400.tavgM_2d_aer_Nx.nc4
	int ParseM2tmnx(std::vector<std::string> values, std::vector<Coord2Dt>& coordsets);

private:
	auto sequential_select(int a[], int n, int key, int& no) -> int;
	auto binary_select(float a[], int n, float key, int& no) -> int;
	auto binary_select(float a[], int n, std::vector<float> keys, int& no) -> int;
	void getAllFiles(std::string path, std::vector<std::string>& files, std::string fileType);

private:
	const char* nc_dir;
	std::mutex mtx; // 创建一个互斥锁

};



